/*
    合并两个有序链表
    将两个升序链表合并为一个新的 
    升序 链表并返回。新链表是通过
    拼接给定的两个链表的所有节点组成的。
*/

#include <stdio.h>

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode {
    int val;
    struct ListNode *next;
};

struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2)
{
    if(l1 ==NULL && l2 != NULL) return l2;
    if(l1 !=NULL && l2 == NULL) return l1;
    if(l1 ==NULL && l2 == NULL) return NULL;

    if(l1->val <= l2->val)
    {
        l1->next = mergeTwoLists(l1->next,l2);
        return l1;
    }
    else
    {
        l2->next = mergeTwoLists(l1,l2->next);
        return l2;
    }
}


int main(int argc, char const *argv[])
{
    struct ListNode l = NULL;

    struct ListNode l1 = NULL;
    struct ListNode l2 = NULL;

    for(int i=0;i<5;i++)
    {
        l1.val = i+1;
        l = (struct ListNode)malloc(sizeof(struct ListNode));
        l1.next = l;
        l1 = l;
    }

    for(int i=0;i<5;i++)
    {
        l2.val = i+1;
        l = (struct ListNode)malloc(sizeof(struct ListNode));
        l2.next = l;
        l2 = l;
    }

    printf()
    mergeTwoLists(&l1,&l2);

    return 0;
}

     tail->next->val = sum%10;
            tail = tail->next;
            tail->next = NULL;
        }
        carry = sum/10;
        if(l1)
        {
            l1 = l1->next;
        }
        if(l2)
        {
            l2 = l2->next;
        }
    }
    if(carry>0)
    {
        tail->next = malloc(sizeof(struct ListNode));
        tail->next->val = carry;
        tail->next->next = NULL;
    }

    return head;
}

int main(int argc, char const *argv[])
{
    
    return 0;
}
